<?php
// +----------------------------------------------------------------------
// | ManniuRead
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://manniuyun.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: heitao <read@manniuyun.com>
// +----------------------------------------------------------------------

namespace app\mall\model;

use think\Model;
use app\mall\model\MallSpecCats as MallSpecCatsModel;

class MallSpecGroups extends Model{
	/**
     * 规格分类名称 - 获取器
     */
    public function getSpecCatidAttr($value){
    	$value = (int)$value;
        if(!$value){
        	return '-';
        }
        $catname = '';
    	$categorys = MallSpecCatsModel::all(function($query){
            $query->field('id,name');
        });
    	foreach ($categorys as $key => $category) {
    		if($category->getAttr('id') == $value){
    			$catname = $category->getAttr('name');
    		}
    	}
        /*
        // 调试模式实时查询
        if(config('app_debug')){
        	$catname = '';
        	$categorys = MallSpecCatsModel::all(function($query){
                $query->field('id,name');
            });
        	foreach ($categorys as $key => $category) {
        		if($category->getAttr('id') == $value){
        			$catname = $category->getAttr('name');
        		}
        	}
        }else{
            // 部署模式使用缓存
            $categorys = cache('mall_categorys');
            if(isset($categorys[$value])){
                $catname = $categorys[$value]['name'];
            }
        }
        */
        return $catname ? $catname : '-';
    }
}